package com.cadre.system.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cadre.common.utils.SecurityUtils;
import com.cadre.common.utils.annotation.SysLog;
import com.cadre.common.utils.common.HttpContextUtils;
import com.cadre.common.utils.common.IPUtils;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.system.domain.officer.A16;
import com.cadre.system.domain.officer.SysLogEntity;
import com.cadre.system.mapper.A16Mapper;
import com.cadre.system.service.A16Service;
import com.cadre.system.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service("a16Service")
/* loaded from: A16ServiceImpl.class */
public class A16ServiceImpl extends ServiceImpl<A16Mapper, A16> implements A16Service {
    @Autowired
    private A16Mapper a16Mapper;
    @Autowired
    private SysLogService sysLogService;

    @Override // com.tdqy.cadre.modular.profess.service.A16Service
    @Transactional(rollbackFor = {Exception.class})
    @SysLog(value = "新增干部考核信息", target = "A01", set = "A16", type = 0)
    public int insertSelective(A16 record) {
        return this.a16Mapper.insertSelective(record);
    }

    @Override // com.tdqy.cadre.modular.profess.service.A16Service
    @Transactional(rollbackFor = {Exception.class})
    public int updateByPrimaryKeySelective(A16 record) {
        return this.a16Mapper.updateByPrimaryKeySelective(record);
    }

    @Override // com.tdqy.cadre.modular.profess.service.A16Service
    @Transactional(rollbackFor = {Exception.class})
    public int deleteByPrimaryKey(String flowid) {
        return this.a16Mapper.deleteByPrimaryKey(flowid);
    }

    @Override // com.tdqy.cadre.modular.profess.service.A16Service
    public List<A16> selectByList(Map<String, Object> map) {
        return this.a16Mapper.selectByList(map);
    }

    @Override // com.tdqy.cadre.modular.profess.service.A16Service
    public String selectByPj(String personid) {
        return this.a16Mapper.selectByPj(personid);
    }

    @Override // com.tdqy.cadre.modular.profess.service.A16Service
    @Transactional(rollbackFor = {Exception.class})
    public int deleteByPersonId(String personid) {
        recordLog(personid);
        return this.a16Mapper.deleteByPersonId(personid);
    }

    private void recordLog(String personid) {
        LambdaQueryWrapper<A16> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(A16::getPersonid, personid);
        List<A16> lists = this.baseMapper.selectList(lambdaQueryWrapper);
        if (lists.size() != 0) {
            String oldParam = JSON.toJSONString(lists);
            SysLogEntity sysLog = new SysLogEntity();
            sysLog.setOldparams(oldParam);
            doSaveLog(sysLog, personid);
        }
    }

    private void doSaveLog(SysLogEntity sysLog, String targetid) {
        sysLog.setOperation("删除干部考核信息");
        sysLog.setOperationtable("A16");
        sysLog.setOperationset("A16");
        sysLog.setOperationtype(2);
        sysLog.setTargetid(targetid);
        sysLog.setParams(targetid);
        sysLog.setIp(IPUtils.getIpAddr(HttpContextUtils.getHttpServletRequest()));
        sysLog.setUsername(SecurityUtils.getLoginUser().getUsername());
        sysLog.setTime(5L);
        sysLog.setCreateDate(new Date());
        this.sysLogService.save(sysLog);
    }

    @Override // com.tdqy.cadre.modular.profess.service.A16Service
    @SysLog(value = "删除干部考核信息", target = "A01", set = "A16", type = DateUtil.SUB_MONTH)
    public int deleteByFlowid(String[] flowid) {
        return this.a16Mapper.deleteBatchIds(Arrays.asList(flowid));
    }
}
